package net.sparrow.gui.screens;

import java.util.ArrayList;

import net.minecraft.src.GuiScreen;
import net.sparrow.gui.drawing.SpScreenCoord;
import net.sparrow.gui.drawing.elements.SpElement;

/**Overrides Minecraft's own GuiScreen
 * to use SpElements instead (and be a little more intelligent).
 *
 */
public class SpScreen extends GuiScreen {

	
	private ArrayList<SpElement> elementList = new ArrayList();
	
	///Only Override These!///
	public void onEvent(SpElement element) {}

	public void init() {}
	
	public void draw() {}
	
	//run when displayScreen() is called
	public void onScreenOpen() {}
	
	//////////////////////////
	
	
	public SpScreen() {
		init();
	}
	
	@Override
	public void keyTyped(char keyChar, int keyCode) {
		super.keyTyped(keyChar, keyCode);
		for(SpElement e : elementList) {
			e.onKeyTyped(keyChar, keyCode);
		}
	}
	
	public void drawScreen(int par1, int par2, float par3) {
		for(SpElement e : elementList) {
			e.draw();
		}
		
		//check if elements need handling
		for(SpElement e : elementList) {
			if( e.isActionWaiting()) {
				onEvent(e);
				e.confirmActionHandled();
			}
		}
		
		draw();
	}
	
	

	
	protected void mouseClicked(int x, int y, int leftOrRight) {
		SpScreenCoord mouseClickCoords = new SpScreenCoord((double)x, (double)y, true).asSpCoords();
		for(SpElement e : elementList) {
			e.onMouseClick(mouseClickCoords, leftOrRight);
		}
	}
}
